﻿using System;
using System.Collections.Generic;
using System.Text;
using Mang24k99.Model.GOLD;
using NHibernate;
using NHibernate.Expression;

namespace Mang24k99.Business.GOLD
{
    public static class BKtGoldProduct
    {

        public static IList<MKtGoldProduct> FindAll()
        {
            return MKtGoldProduct.SelectAll();
        }

        public static MKtGoldProduct Find(object ID)
        {
            return MKtGoldProduct.SelectByPrimaryKey(ID);
        }

        public static IList<MKtGoldProduct> FindALLByProperty(string property, object value)
        {
            return MKtGoldProduct.SelectALLByProperty(property, value);
        }

        public static IList<MKtGoldProduct> FindALLSliced(int firstResult, int maxResult)
        {
            DetachedCriteria criteria = null;
            return MKtGoldProduct.SelectALLSliced(firstResult, maxResult, criteria);
        }
        /// <summary>
        /// 通过机构和金品品种查询机构所维护的产品
        /// </summary>
        /// <param name="orglistno"></param>
        /// <param name="goldtype"></param>
        /// <returns></returns>
        public static IList<MKtGoldProduct> SelectByWhere(int orglistno,int goldtype)
        {
            string where = " where goldproduct.MKtCommOrglist.OrgnizeNO="+orglistno;
                    where+=" and goldproduct.MKtGoldGoldbreed.MKtCommCodelist.CODE_NO="+goldtype;
                    where += " and goldproduct.CloseShow=0";
                    where += " order by goldproduct.PageOrder,goldproduct.ID";
            return (IList<MKtGoldProduct>) MKtGoldProduct.SelectBywhere(where);
        }
        /// <summary>
        /// 通过机构和金品品种查询机构可首页排序的报价产品（报价未关闭，未加入首页排序）
        /// ismporder=1：已经加入首页排序的产品；ismporder=0：未加入首页排序的产品
        /// 目前只有银行的金条，金章有首页排序
        /// </summary>
        /// <param name="orglistno"></param>
        /// <param name="goldtype"></param>
        /// <returns></returns>
        public static IList<MKtGoldProduct> SelectOrglistProduct(int orglistno, int goldtype,int ismporder)
        {
            string where = " where goldproduct.MKtCommOrglist.OrgnizeNO=" + orglistno;
            where += " and goldproduct.Is_Mporder=" + ismporder;
            where += " and goldproduct.CloseShow=0";
            where += " and goldproduct.MKtGoldGoldbreed.MKtCommCodelist.CODE_NO=" + goldtype;
            where += " order by goldproduct.PageOrder,goldproduct.ID";
            return (IList<MKtGoldProduct>)MKtGoldProduct.SelectBywhere(where);
        }
        /// <summary>
        /// 通过机构编号与金品编号查找记录
        /// </summary>
        /// <param name="orglistno"></param>
        /// <param name="breedno"></param>
        /// <returns></returns>
        public static IList<MKtGoldProduct>SelectProduct(int orglistno,int breedno)
        {
            MKtGoldProduct goldproduct = new MKtGoldProduct();
            string where = "where goldproduct.MKtCommOrglist.OrgnizeNO="+orglistno;
                    where+=" and goldproduct.MKtGoldGoldbreed.BreedNO="+breedno;
            return (IList<MKtGoldProduct>) MKtGoldProduct.SelectBywhere(where);
        }
        /// <summary>
        /// 通过机构编号、金品编号、重量、规格查找记录(验证金条，金币，银条类产品是否重复)
        /// </summary>
        /// <param name="orglistno"></param>
        /// <param name="breedno"></param>
        /// <returns></returns>
        public static IList<MKtGoldProduct> SelectProductBySpec(int orglistno, int breedno,int measurement,int unitno)
        {
            MKtGoldProduct goldproduct = new MKtGoldProduct(); 
            string where = "where goldproduct.MKtCommOrglist.OrgnizeNO=" + orglistno;
            where += " and goldproduct.MKtGoldGoldbreed.BreedNO=" + breedno;
            where += " and goldproduct.MEASUREMENT=" + measurement;
            where += " and goldproduct.MKtCommCodelist.CODE_NO=" + unitno;
            return (IList<MKtGoldProduct>)MKtGoldProduct.SelectBywhere(where);
        }
        /// <summary>
        /// 查询可进行首页排序的产品（银行机构维护的产品，未关闭报价显示）
        /// ismporder=1：已经加入首页排序的产品；ismporder=0：未加入首页排序的产品
        /// </summary>
        /// <returns></returns>
        public static IList<MKtGoldProduct>SelectSortProduct(int ismporder)
        {
            string where = " where goldproduct.MKtCommOrglist.ParentNO=3 and goldproduct.Is_Mporder="+ismporder;
            where += " and goldproduct.CloseShow=0 order by goldproduct.MpageOrder,goldproduct.ID";
            return (IList<MKtGoldProduct>)MKtGoldProduct.SelectBywhere(where);
        }
    }
}
